package com.zy.openchat.core.model.redpacket;

import android.os.Parcel;
import android.os.Parcelable;

import com.zy.openchat.core.model.user.UserInfo;

public class RP_Pick_Msg implements Parcelable {
    //通话标识
    public long redPacketId;
    //红包创建人
    public long from;
    //1.单聊红包 2.拼手气红包 3.普通红包
    public int type;
    //单个红包金额
    public float price;
    //是否最后一个红包
    public boolean isLast;

    public String description(long whoGot) {
        if (from == UserInfo.getUserInfo().id) {//当前用户创建的红包
            if (whoGot == from) {//自己领取了自己的红包
                return "你领取了自己发的红包";
            } else {//他人领取
                if (type == 1) {//单聊红包
                    return String.format("%s领取了你的红包", UserInfo.userDisplayName(whoGot));
                } else {
                    if (isLast) {
                        return String.format("%s领取了你的红包，你的红包已被领完", UserInfo.userDisplayName(whoGot));
                    } else {
                        return String.format("%s领取了你的红包", UserInfo.userDisplayName(whoGot));
                    }
                }
            }
        } else {//其他用户创建的红包
            if (whoGot == UserInfo.getUserInfo().id) {
                return "你领取了红包";
            } else {
                return String.format("%s领取了红包", UserInfo.userDisplayName(whoGot));
            }
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.redPacketId);
        dest.writeLong(this.from);
        dest.writeInt(this.type);
        dest.writeFloat(this.price);
        dest.writeByte(this.isLast ? (byte) 1 : (byte) 0);
    }

    public RP_Pick_Msg() {
    }

    protected RP_Pick_Msg(Parcel in) {
        this.redPacketId = in.readLong();
        this.from = in.readLong();
        this.type = in.readInt();
        this.price = in.readFloat();
        this.isLast = in.readByte() != 0;
    }

    public static final Creator<RP_Pick_Msg> CREATOR = new Creator<RP_Pick_Msg>() {
        @Override
        public RP_Pick_Msg createFromParcel(Parcel source) {
            return new RP_Pick_Msg(source);
        }

        @Override
        public RP_Pick_Msg[] newArray(int size) {
            return new RP_Pick_Msg[size];
        }
    };
}
